package com.ruoyi.web.controller;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.web.service.IQgPayRechargeDetailService;
import com.ruoyi.web.service.IQgPayWithdrawalDetailService;
import com.ruoyi.web.utils.qg_pay.config.QGPayConfig;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 法币充值Controller
 *
 * @date 2023-03-13
 */
@RestController
@RequestMapping("/qg-pay")
@AllArgsConstructor
public class QGPayController extends BaseController {

    private final QGPayConfig qgConfig;
    private final IQgPayRechargeDetailService qgPayRechargeDetailService;
    private final IQgPayWithdrawalDetailService qgPayWithdrawalDetailService;

    /**
     * QGPay 代收通知
     * <p>代收通知：{"amount":"1.00","businessCode":"100004","orderNo":"202303141085253212083335168","payAmount":"1.00","sign":"XbtMtMGeQDV_4vwOBLkqURPggdSN-Lwsn_FIEE5es_x63MKJtBtPOzUIEVHl97o6JuOZXCw4DFlv3qOQef8ScGhDwp6YikTvK5YV-NXqam5ZajDl52n31RiJr2oRdklzFqJHjJpWZEV9eiCcKJM8hS4mh-IVwoUDZQLk50o5rbV0irHBj6j43zaqB1nubIax-OSa5z9TYBLSXj18bIBR6LJVO-6kAu_RcSnqSnjtkPPgUbUmdJERx8O1vQdQ5yUpkpoluzsQNqqaQiswCiNMHrmoEVgKnyxAxjUfLzKOhd5iVRNMQQsUkCk9dJR31ycXrRLbcvgOA-oxuheSzTyc0A","merchant":"1000009","message":"success","merchantOrderNo":"1635573680171130880","status":"success","pay_time":"2023-03-14 09:29:56"}
     *
     * @param str 代收通知
     * @return {@link String}
     * @since 2023/3/14 17:03
     */
    @Anonymous
    @PostMapping("/notify/order-pay")
    public String qgOrderPayNotify(@RequestBody String str) {
        qgPayRechargeDetailService.qgOrderPayNotify(JSONObject.parseObject(str));
        return "SUCCESS";
    }

    /**
     * QGPay 代付通知
     * <p>代付通知：{"amount":"1.00","businessCode":"100005","orderNo":"202303151085572104693493760","payAmount":"1.00","sign":"XPbWvKIqWZGmX9sXlRD4ELLBCuJakB5RF6DsFIg881ZhMfNc0KcMTSDyL0Rkkt3-Mv6EIwuC12BWFfheej82isTUrvnr7Ydvclfhedohx3LLdA9ItfWH88vq6oG9qq-0MGzaPbghXTAx8CsME-OwpOWzPcVV88tTOK34vmIXuUc9zj4je2SOW4Y3WVidV0Y_hbFjH9UxnIz-EKG-v2tOqTdBOzMJqXT0tCWJZ9EKO9YYrK4TJh4vyJChZW8JiSQ5NNMgZpUAc2zOA3T5rMLmS1SEmPYFgjrWNhWiZ8rkhKki47Mm6eJPB_c4g9cfy9XYloovvgqhOPn2Ei3u7HWLMQ","merchant":"1000009","message":"success","merchantOrderNo":"1635892574677209088","status":"success","pay_time":"2023-03-15 06:49:10"}
     *
     * @param str 代付通知
     * @return {@link String}
     * @since 2023/3/14 17:03
     */
    @Anonymous
    @PostMapping("/notify/single-order")
    public String qgSingleOrderNotify(@RequestBody String str) {
        qgPayWithdrawalDetailService.qgSingleOrderNotify(JSONObject.parseObject(str));
        return "SUCCESS";
    }
}
